define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'iotgoods/index',
                    add_url: 'iotgoods/add',
                    edit_url: 'iotgoods/edit',
                    del_url: 'iotgoods/del',
                    multi_url: 'iotgoods/multi',
                    table: 'iotgoods',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'merid', title: __('Merid')},
                        {field: 'goods_id', title: __('Goods_id')},
                        {field: 'name', title: __('Name')},
                        //{field: 'cate', title: __('Cate'), visible:false, searchList: {"4":__('Cate 4')}},
                        {field: 'cate_text', title: __('Cate'), operate:false},
                        {field: 'isp', title: __('Isp')},
                        {field: 'pkg', title: __('Pkg')},
                        {field: 'month', title: __('Month')},
                        //{field: 'month_text', title: __('Month'), operate:false},
                        {field: 'des', title: __('Des')},
                        {field: 'timeline', title: __('Timeline'), operate:'RANGE', addclass:'datetimerange'},
                        {field: 'price', title: __('Price'), operate:'BETWEEN'},
                        //{field: 'bprice', title: __('Bprice'), operate:'BETWEEN'},
                        //{field: 'sorts', title: __('Sorts')},
                        {field: 'sale_text', title: __('Sale'), searchList: {"n":__('否'), "y":__('是')}},
                        {field: 'rebate_amount', title: __('Rebate_amount'), operate:'BETWEEN'},
                        //{field: 'rebate_rule', title: __('Rebate_rule'), visible:false, searchList: {"1":__('Rebate_rule 1')}},
                        {field: 'rebate_rule_text', title: __('Rebate_rule'), operate:false},
                        {field: 'user_rebate1', title: __('User_rebate1'), operate:'BETWEEN'},
                        {field: 'user_rebate2', title: __('User_rebate2'), operate:'BETWEEN'},
                        {field: 'user_rebate3', title: __('User_rebate3'), operate:'BETWEEN'},
                        {field: 'agent_rebate1', title: __('Agent_rebate1'), operate:'BETWEEN'},
                        {field: 'agent_rebate2', title: __('Agent_rebate2'), operate:'BETWEEN'},
                        {field: 'agent_rebate3', title: __('Agent_rebate3'), operate:'BETWEEN'},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});